a = int(input())
s=0
r=0
if 1000 <= a <= 9999:
    d = 0
    for i in range (2, a):
        if a % i == 0:
            d += 1
    if d == 0:
        print(a)
    elif d > 0:
        s = a % 1000
        r = a // 10
        d = 0
        for i in range (2, s):
            if s % i == 0:
                d += 1
        if d == 0:
            print(s)
        else:
            d = 0
            for i in range (2, r):
                if r % i == 0:
                    d += 1
            if d == 0:
                print(r)
            else:
                print(0)
    else:
        print(0)
else:
    print(0)